package day14.KeJian;
/*- 定义一个类MyRunnable实现Runnable接口
- 在MyRunnable类中重写run()方法
- 创建MyRunnable类的对象
- 创建Thread类的对象，把MyRunnable对象作为构造方法的参数
- 启动线程*/
public class MyRunnable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            //Thread(Runnable target)分配一个新的Thread对象
            System.out.println(Thread.currentThread().getName()+":"+i);

        }
    }
}
class MyRunnableDemo{
    public static void main(String[] args) {
        //创建MyRunnable类的对象
        MyRunnable my = new MyRunnable();

        //创建Thread类的对象，把MyRunnable对象作为构造方法的参数
        //Thread t1 = new Thread(my);
        //Thread t2 = new Thread(my);
        Thread t1 = new Thread(my,"123");
        Thread t2 = new Thread(my,"456");

        //启动线程
        t1.start();
        t2.start();
    }
}
